package com.model.speelveld.monsters;

import android.os.CountDownTimer;

import com.model.speelveld.GameModel;
import com.model.speelveld.Level;
import com.model.speelveld.Path;
import com.view.speelveld.GameObject;
import com.view.speelveld.GameView;

public abstract class Monster extends GameObject {

	
	private int health;
	private int value;
	private int level;
	private int score;
	private Path position;
	private Level map;
	private GameView gv;
	private CountDownTimer speed;
	private GameModel gameModel;	
	
	public Monster(int level, GameView gv, Level map, GameModel gm , int health ,int score , int value)
	{
		super(GameView.NORMAL_MONSTER);
		this.gameModel = gm;
		this.gv = gv;
		this.map = map;
		this.level = level;
		this.position = map.getStartPosition();
		this.health = health;
		this.score = score;
		this.value = value;
	}
	
	public void setMap(Level map)
	{
		this.map = map;
	}
	
	public Path getPosition()
	{
		return position;
	}
	
	public void setSpeed(long ms)
	{
		speed = new CountDownTimer(ms, ms){

		     @Override
			public void onTick(long millisUntilFinished) {
		         //mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
		     }

		     @Override
			public void onFinish() {
		    	 moveMonster();
		     }
		  }.start();
	}


	public void moveMonster()
	{
		position = map.getNextPath(position);
		if(position == null)
		{
			gameModel.removeLive();
			speed.cancel();
			gv.deleteMonster(this);
			return;
		}
		gv.moveMonster(this);
		speed.start();
	}
	
	public void calcValue()
	{
		value = 50 + (level * 10);
	}

	
	public int getHealth() {
		return health;
	}


	public void removeHealth(int damage) {
		this.health -= damage;
	}


	public int getScore() {
		return score;
	}


	public void setScore(int score) {
		this.score = score;
	}


	public int getValue() {
		return value;
	}


	public void setValue(int value) {
		this.value = value;
	}


	public int getLevel() {
		return level;
	}


	public void setLevel(int level) {
		this.level = level;
	}
	public void Destroy()
	{
		gameModel.addMoney(value);
		gameModel.enemyKilled();
		gameModel.addScore(score);
		
		// Hier wordt de damage het desbetreffende projectiel uitdeelt
		speed.cancel();
		gv.updateField();
		gv.postInvalidate();
	}

	
	
}
